package com.course.designpatterns.singleton;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/6/20 20:53
 * @description：饿汉式
 * 类加载时加载，就实例化一个，JVM保证线程安全
 * 简单实用，推荐使用。
 *
 */
public class Mgr02
{
    private static Mgr02 INSTANCE;

    static {
        INSTANCE = new Mgr02();
    }

    private Mgr02(){};

    public static Mgr02 getInstance(){
        return INSTANCE;
    }

    public static void main(String[] args)
    {
        //获取两次实例
        Mgr02 m1 =  Mgr02.getInstance();
        Mgr02 m2 =  Mgr02.getInstance();
        System.out.println(m1 == m2);

    }


}
